import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: 花海
 * Date: 2022-10-23
 * Time: 12:47
 */
public class Main {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();

        list.add(1);
        list.add(1);

        int i = 1;
        while (list.get(i)<1000000){
            list.add(list.get(i)+ list.get(i-1));
            i++;
        }
        Scanner sc=new Scanner(System.in);
        while(sc.hasNextInt()){
            int num=sc.nextInt();
            int min=1000000;
            for (int j = 0; j < list.size(); j++) {
                int chaju=num- list.get(j);
                if(chaju<0){
                    chaju=-chaju;
                }
                if(chaju<min){
                    min=chaju;
                }
            }
            if(min<0){
                System.out.println(-min);
            }else {
                System.out.println(min);
            }
        }


    }

}